package com.welsy.authoring.vo
{
	import com.welsy.authoring.view.coursecomponents.*;
	import com.welsy.authoring.vo.course.pattern.*;
	import com.welsy.authoring.model.CourseModelLocator;		
	
	[Bindable]			
	public class CourseComponentsVO extends CourseItem 
	{
						
      public var course:CourseVO = new CourseVO;
      
      private var _items:Array;
      
      private var _load:Boolean = false;

      public function CourseComponentsVO() {
         _items = new Array();
      }

      override public function addItem(item:ICourseItem):void {
         _items.push(item);
      }

      override public function removeItem(item:ICourseItem):void {
         var i:uint;
         // Loop through all the child elements.
         for(i = 0; i < _items.length; i++) {
            // If one of the elements matches the 
            // parameter remove it from the array.
            if(_items[i] == item) {
               _items.splice(i, 1);
               break;
            }
         }
      }
      override public function iterator():ICourseIterator {
         
         return new ArrayCourseIterator(_items);
      }
      
      public function getCollection():Array {         
         return _items;
      }
      
      //ricarica il corso nel caso in cui sia già stato caricato
      public function reload():void {         
         if (_load == false)
   			_load = true
   		 else {
   		 	var courseSelect:CourseComponentsVO
            courseSelect = this
            var model:CourseModelLocator = CourseModelLocator.getInstance()
            model.selectedCourse = new CourseComponentsVO
            model.selectedCourse = courseSelect
      	 }
      } 
      
      public function enablePreview():Boolean {
      	if (getCollection().length == 0)
      		return false
      	else
      		return true
      } 
  }
}